import { defineStore } from 'pinia'
import request  from '@/utils/request'
import { IApiRes,  categoryItem, cateItem, cateRes } from '@/types/data'
import { topCategory } from '../constants'

const topCategoryList = topCategory.map(item => {
    return {
        id: item,
        name:item
    }
})

export default defineStore('category', {
    state() {
        return {
            list: topCategoryList as categoryItem[],
            categoreList: {} as cateRes
        }
    },
    actions: {
        async getCAtegoryList() {
            const res = await request.get<IApiRes<categoryItem[]>>('/home/category/head')
            // console.log(res.data.result);
            this.list = res.data.result
        },
        async getTopCategory(id:string) {
            const res = await request.get<IApiRes<cateRes>>('category',{
                params:{id:id}
            })
            // console.log(res.data.result);
            this.categoreList = res.data.result
        }
    }
})
